export default {
  data() {
    return {
      crossBorderTypeEventFlag: false,
      selectionGoodsTypeEventFlag: false,
      sellPriceEventFlag: false,
      publicPlatfromAuthorityEventFlag: false
    }
  },
  mounted() {
  },
  methods: {
    // 绑定跨境类型切换事件
    bindChangeCrossBorderType(callback) {
      if (typeof (callback) !== 'function') {
        return
      }
      this.crossBorderTypeEventFlag = true
      this.$bus.$on('crossBorderTypeEvent', callback)
    },
    // 触发跨境类型切换事件
    emitChangeCrossBorderType(crossBorderType) {
      this.$bus.$emit('crossBorderTypeEvent', crossBorderType)
    },

    // 绑定选品小程序勾选事件
    bindSelectionGoodsType(callback) {
      if (typeof (callback) !== 'function') {
        return
      }
      this.selectionGoodsTypeEventFlag = true
      this.$bus.$on('selectionGoodsTypeEvent', callback)
    },
    // 触发选品小程序勾选事件
    emitChangeSelectionGoodsType(selectionGoodsType) {
      this.$bus.$emit('selectionGoodsTypeEvent', selectionGoodsType)
    },

    // 绑定选择公域平台事件
    bindPublicPlatfromAuthority(callback) {
      if (typeof (callback) !== 'function') {
        return
      }
      this.publicPlatfromAuthorityEventFlag = true
      this.$bus.$on('publicPlatfromAuthorityEvent', callback)
    },
    // 触发选择公域平台事件
    emitPublicPlatfromAuthority(publicPlatfromAuthority) {
      this.$bus.$emit('publicPlatfromAuthorityEvent', publicPlatfromAuthority)
    },

    // 绑定零售价改变事件
    bindChangeSellPrice(callback) {
      if (typeof (callback) !== 'function') {
        return
      }
      this.sellPriceEventFlag = true
      this.$bus.$on('sellPriceEvent', callback)
    },
    // 触发零售价改变事件
    emitChangeSellPrice(sellPrice) {
      const price = parseFloat(sellPrice)
      const finalPrice = isNaN(price) ? 0 : price
      this.$bus.$emit('sellPriceEvent', finalPrice)
    }
  },
  beforeDestroy() {
    if (this.crossBorderTypeEventFlag) {
      this.$bus.$off('crossBorderTypeEvent')
    }
    if (this.selectionGoodsTypeEventFlag) {
      this.$bus.$off('selectionGoodsTypeEvent')
    }
    if (this.sellPriceEventFlag) {
      this.$bus.$off('sellPriceEvent')
    }
    if (this.publicPlatfromAuthorityEventFlag) {
      this.$bus.$off('publicPlatfromAuthorityEvent')
    }
  }
}
